//created by: Huiyi

Ext.define('MajorProjectSenchaTouch.controller.AdditionalResources', {
    extend: 'Ext.app.Controller',
	requires: [
    'Ext.util.DelayedTask'
    ],
	
    config:{
        views: ['CitationModule.Citation','LibraryVideosModule.LibraryVideos'],
		
		fullscreen:true,
		
        refs:{
            navView: 'mainNavView',

            Citation: 'button[action=goCitationPage]',
            LibraryVideos: 'button[action=goLibraryVideosPage]',
        },

       control:{
           Citation:{
               tap: 'goCitationPage'
           },
           LibraryVideos:{
               tap: 'goLibraryVideosPage'
           },
       }
   },


	goCitationPage: function(){
        var ctrl = this;
        var previousPage = ctrl.showMask();
       
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.pushView('Citation', 'citationpage');
            ctrl.hideMask(previousPage); 
            
            ctrl.applyNavUrl('citationpage');
        });
        task.delay(1);
    },
   
	

	
	goLibraryVideosPage: function(){
	
		this.loadvideostore();
    },
	
	loadvideostore: function(){
		var scope = this;
		//get the store
        var videoInfoStore = Ext.getStore('LibraryVideosInfo');
		
		//clear the store
        videoInfoStore.removeAll();

		//load the store
		videoInfoStore.load({
			callback: function(records, operation, success) {
			
			//show the result page
            scope.pushView('Library videos', 'libvidpage');

			},//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'LibraryVideos/getLibraryvideos/' 
		
		})
	
	},
   
    hideMask: function(previousPage){        
        previousPage.setMasked(false);
    },
    pushView: function(setTitle, setXtype){
        var view = this.getNavView();
        
        view.push({
            title: setTitle,
            xtype: setXtype
        })
    },
	showMask: function(){
        var view = this.getNavView();
        var previousPage = view._activeItem;
        
        previousPage.setMasked({
            xtype: 'loadmask',
            message: 'Please wait...'
        });
        
        return previousPage;
    },
	  applyNavUrl: function(urlLink){
        this.getApplication().getHistory().add(new Ext.app.Action({
            url: urlLink
        }), true);  
    }
	
	

    
});

